module.exports = function ($scope, $resource, getDate, toaster) {

    var today = new Date();
    $scope.dataIndex = {};
    $scope.data1 = [];
    $scope.data2 = [];
    $scope.chart = {
        'linename': ["原粉丝量(人)", "今日新增(人)"],
        'data': [[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]],
        'xaxis': []
    }
    
    $scope.getFunsCount = function(){
        $resource('/api/as/mc/userfans/getFunsCountList', {}, {}).save({}, function (res) {
            if (res.errcode === 0) {
                for(var i = 0; i < res.data.length; i++){
                    var temp = res.data[i];
                    var index = $scope.dataIndex['a'+temp.create_time1];
                    if(index >= 0){
                        $scope.chart.data[0][index] = temp.row_num-temp.new_num;
                        $scope.chart.data[1][index] = temp.new_num;
                    }
                    if(temp.create_time1 == 'a' && $scope.chart.data[0][0] == 0){
                        $scope.chart.data[0][0] = temp.row_num;
                    }
                }
                
                for(var i = 0; i < 7; i++){
                    if($scope.chart.data[0][i] == 0){
                        $scope.chart.data[0][i] = $scope.chart.data[0][i-1] + $scope.chart.data[1][i-1];
                    }
                    $scope.data1.push({'index': i, 'num': $scope.chart.data[0][i]});
                    $scope.data2.push({'index': i, 'num': $scope.chart.data[1][i]});
                }
            } else {
                toaster.error({ title: '', body: '粉丝分析失败'});
            }
        });
    }
    
    init();
    function init(){
        today.setDate(today.getDate() - 6);
        for(var i = 0; i < 7; i++){
            $scope.chart.xaxis[i] = getDate(today);
            $scope.dataIndex['a'+$scope.chart.xaxis[i]] = i;
            today.setDate(today.getDate() + 1);
        }
        $scope.getFunsCount();
    }
    


    

};